Refactor widget prefs 6177951123037805482#118
Conversation
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
- Implemented permission result handling in MainActivity to refresh data or show feedback. - Replaced hardcoded SimpleDateFormat with DateUtils in CalendarCard to respect user time format preference. - Added TODO in MainViewModel regarding hardcoded news category. - Replaced e.printStackTrace() with Log.e() in repositories for better error tracking. - Added TAG constants to repositories.
- Implemented permission result handling in MainActivity. - Replaced hardcoded date format with DateUtils in CalendarCard. - Re-implemented dynamic news category selection in MainViewModel. - Added isLoading state to MainViewModel. - Replaced e.printStackTrace() with Log.e() in repositories. - Updated repositories to return Boolean success/failure status. - Implemented transactional replaceAll in ArticleDao/NewsRepository to prevent data loss. - Implemented retry logic in WidgetUpdateWorker based on refresh success. - Created missing colors.xml to fix build failure. - Implemented settings navigation in HomeScreen.
- Implemented permission result handling in MainActivity. - Replaced hardcoded date format with DateUtils in CalendarCard. - Re-implemented dynamic news category selection in MainViewModel. - Added isLoading state to MainViewModel. - Fixed combine function signature in MainViewModel to handle 8 flows. - Replaced e.printStackTrace() with Log.e() in repositories. - Updated repositories to return Boolean success/failure status. - Implemented transactional replaceAll in ArticleDao/NewsRepository to prevent data loss. - Implemented retry logic in WidgetUpdateWorker based on refresh success. - Created missing colors.xml to fix build failure. - Implemented settings navigation in HomeScreen.
…Repository.kt Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
- Implemented permission result handling in MainActivity. - Replaced hardcoded date format with DateUtils in CalendarCard. - Re-implemented dynamic news category selection in MainViewModel. - Added isLoading state to MainViewModel. - Fixed combine function signature in MainViewModel to handle 8 flows. - Replaced e.printStackTrace() with Log.e() in repositories. - Updated repositories to return Boolean success/failure status. - Implemented transactional replaceAll in ArticleDao/NewsRepository to prevent data loss. - Implemented retry logic in WidgetUpdateWorker based on refresh success. - Created missing colors.xml to fix build failure. - Implemented settings navigation in HomeScreen. - Fixed syntax error in CalendarRepository.
- Implemented permission result handling in MainActivity. - Replaced hardcoded date format with DateUtils in CalendarCard. - Re-implemented dynamic news category selection in MainViewModel. - Added isLoading state to MainViewModel. - Refactored MainViewModel combine logic to use chained calls for type safety. - Replaced e.printStackTrace() with Log.e() in repositories and DayAheadWidget. - Updated repositories to return Boolean success/failure status. - Implemented transactional replaceAll in ArticleDao/NewsRepository. - Implemented retry logic in WidgetUpdateWorker. - Created missing colors.xml to fix build failure. - Implemented settings navigation in HomeScreen. - Fixed CalendarRepository syntax error and extracted magic number. - Added @JvmStatic to AppUtils for Java interop. - Extracted Hilt versions in build.gradle. - Added null/blank title filtering in NewsRepository.
- Implemented permission result handling in MainActivity. - Replaced hardcoded date format with DateUtils in CalendarCard. - Re-implemented dynamic news category selection in MainViewModel. - Added isLoading state to MainViewModel. - Refactored MainViewModel combine logic to use chained calls for type safety. - Replaced e.printStackTrace() with Log.e() in repositories and DayAheadWidget. - Updated repositories to return Boolean success/failure status. - Implemented transactional replaceAll in ArticleDao/NewsRepository. - Implemented retry logic in WidgetUpdateWorker. - Created missing colors.xml to fix build failure. - Implemented settings navigation in HomeScreen. - Fixed CalendarRepository syntax error and extracted magic number. - Added @JvmStatic to AppUtils for Java interop. - Extracted Hilt versions in build.gradle. - Added null/blank title filtering in NewsRepository. - Implemented location fetching in MainActivity and updated MainViewModel. - Updated Geocoder usage for API 33+.
- Updated `fetchLocationName` in `MainViewModel` to use `suspendCancellableCoroutine` for the Tiramisu `Geocoder` API, preventing a race condition where the coroutine scope would close before the callback fired. - Refactored `DayAheadWidget` to inject `WeatherRepository` instead of `WeatherDao` and `Gson`. - Simplified `DayAheadWidget.onUpdate` to fetch parsed weather data directly from the repository flow, removing data access and parsing logic from the UI component.
- Created `UserPreferencesRepository` to encapsulate SharedPreferences access and expose flows for user preferences. - Updated `MainViewModel` to inject `UserPreferencesRepository` instead of direct SharedPreferences usage. - Fixed race condition in `MainViewModel` Geocoder logic by implementing `GeocodeListener`. - Updated `HomeScreen` to launch `SettingsActivity` on weather card click.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Refactored DayAheadWidget and WidgetUpdateWorker to use UserPreferencesRepository instead of accessing SharedPreferences directly. This improves architectural consistency and centralizes data access logic. Changes: - Updated UserPreferencesRepository to expose summary flow and hasLocation method. - Updated DayAheadWidget to inject UserPreferencesRepository and collect summary flow. - Updated WidgetUpdateWorker to inject UserPreferencesRepository and use it for location check, preference retrieval, and summary saving.
Summary of ChangesHello @harrydbarnes, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request delivers a comprehensive architectural upgrade, transitioning the application from a legacy Java-based Android View system to a modern Kotlin-first stack. By adopting Jetpack Compose for the user interface, Hilt for dependency injection, and Room for local data persistence, the changes significantly enhance the app's maintainability, scalability, and overall developer experience. The refactoring centralizes data management through a new repository layer, ensuring a more robust and consistent approach to handling information across all features, including the DayAhead widget. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
The pull request refactors the DayAheadWidget and WidgetUpdateWorker to use UserPreferencesRepository for better architectural consistency. It also adds summary flow and location check to the repository. The changes include migrating from Java to Kotlin, incorporating Hilt for dependency injection, Room for local data persistence, and Compose for UI. The MainActivity is also converted to Kotlin and uses Compose for the UI. The DashboardAdapter, associated layouts, and older models are removed as part of the migration to Compose.
| <uses-permission android:name="android.permission.health.READ_STEPS" /> | ||
|
|
||
| <application | ||
| android:name=".TheLoopApplication" |
| id 'org.jetbrains.kotlin.kapt' version '1.9.10' | ||
| id 'com.google.dagger.hilt.android' |
| lateinit var weatherRepository: WeatherRepository | ||
|
|
||
| @Inject | ||
| lateinit var userPreferencesRepository: UserPreferencesRepository |
| if (!userPreferencesRepository.hasLocation()) { | ||
| return Result.success() | ||
| } |
| suspend fun fetchWeather(lat: Double, lon: Double) { | ||
| fetchLocationName(lat, lon) | ||
| weatherRepo.refresh(lat, lon, userPrefsRepo.tempUnit.first()) | ||
| } |
| // Return true to prevent WidgetUpdateWorker from retrying indefinitely | ||
| return@withContext true | ||
| } |
There was a problem hiding this comment.
Refactored DayAheadWidget and WidgetUpdateWorker to use UserPreferencesRepository for better architectural consistency. Added summary flow and location check to the repository.